package ch08;

public class DataSet 
{
	private double sum;
	private Object maximum;
	private int count;
	private IMeasurer measurer;
	
	public DataSet(IMeasurer m)
	{
		sum = 0;
		count = 0;
		maximum = null;
		measurer = m;
	}
	
	public void add(Object o)
	{
		sum += measurer.measure(o);
		if(count == 0 || measurer.measure(maximum) < measurer.measure(o)){
			maximum = o;
		}
		count ++;
	}
	
	public double getAverage()
	{
		if (count == 0)
		{
			return 0;
		} else {
			return sum / count;
		}		
	}
	
	public Object getMaximum()
	{
		return maximum;
	}
	
}
